# -*- coding: UTF-8 -*-
"""
描述：本段代码定时从无忧代理API接口获取代理IP，存入IP池中
"""
import requests
import time
import threading

from . import dataip5


# 获取代理IP的线程类
class GetIpThread(threading.Thread):
    def __init__(self, apiUrl, fetchSecond):
        super(GetIpThread, self).__init__()
        self.fetchSecond = fetchSecond
        self.apiUrl = apiUrl

    def run(self):
        while True:
            # 获取IP列表
            res = requests.get(self.apiUrl).content.decode()
            # 按照\n分割获取到的IP
            dataip5.IPPOOL = res.split('\n')
            # 休眠
            time.sleep(self.fetchSecond)


'''
# 无忧代理ip提取线程
    order = "61f2fb533e331ae9a4a0f543a82b4769"
    # 获取IP的API接口
    apiUrl = "http://api.ip.data5u.com/dynamic/get.html?order=" + order
    # 获取IP时间间隔，建议为5秒
    fetchSecond = 10
    # 开始自动获取IP
    GetIpThread(apiUrl, fetchSecond).start()
'''